package yifeng.easymock;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;

import javax.servlet.http.HttpServletRequest;

import org.easymock.EasyMock;

public class Test {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		HttpServletRequest mockRequest = null;
		BufferedReader br = null;
		InputStreamReader read = null;
		File f = null;

		f = new File("D:/111.txt");
		read = new InputStreamReader(new FileInputStream(f), "UTF-8");
		br = new BufferedReader(read);
		//伪造请求
		mockRequest = EasyMock.createNiceMock(HttpServletRequest.class);
		mockRequest.getReader();
		EasyMock.expectLastCall().andReturn(br);
		EasyMock.replay(mockRequest);
		
		
		BufferedReader r2 = mockRequest.getReader();
		
		String str;
		while((str = r2.readLine()) != null){
			System.out.println(str);
		}
		
		
		System.out.println("------");
		BufferedReader r3 = mockRequest.getReader();
		
		String str1;
		while((str1 = r3.readLine()) != null){
			System.out.println(str1);
		}
		
	}

}
